<?php
/**
 * @package pmapi
 * @copyright Copyright (c)2014 Enrico Fagnoni
 * @license GNU General Public License version 3, or later
 *
 * @since 1.0.0
 */
 
defined('_JEXEC') or die;


class UriHelper
{
    private static $_namespace = array() ;
 
    
        
    public static function setLanguageProfile(array $profile)
    {
        self::$_namespace = $profile;
    }
    
    
    public static function getLanguageProfile()
    {
        return self::$_namespace;
    }

    
    public static function getNamespace($prefix)
    {
        return self::$_namespace[$prefix];
    }
    
    
    private static function _mhURI($type,$container=null,$id=null,$reference=null)
    {
        $uri = 'index.php?option=com_pmapi&format='.$type;
        if ($container) $uri .= '&view='.$container;
        if ($id)        $uri .= '&id='.$id;
        if ($reference) $uri .= '#'.$reference;
        
        return JRoute::_($uri);        
    }


    public static function mkResourceURI($container=null,$id=null,$reference='this')
    {
        return self::_mhURI('data',$container,$id,$reference);
    } 
  
  
    public static function mkDataURL($container=null,$id=null)
    {
        return self::_mhURI('data',$container,$id,null);
    }  
    
    
    public static function mkHtmlURL($container=null,$id=null)
    {
        return self::_mhURI('html',$container,$id,null);
    }    
   

    public static function mkNamespace($container=null,$id=null)
    {
        // Add X as a place holder and then remove it. This works with seo
        if (!$container) {
            $uri = self::mkDataURL('X');
        } elseif ($container && !$id) {
            $uri = self::mkDataURL($container,'X');
        } else {
            $uri = self::mkDataURL($container,$id,'X');
        }
        
        return substr($uri, 0, -1);
    }


    
    public static function getCurrenUserURI()
    {
        return self::mkResourceURI('user', JFactory::getUser()->id);
    } 

}

